<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1, user-scalable=no">
  <meta content="yes" name="apple-mobile-web-app-capable">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title><%= title %></title>
    <link rel='stylesheet' href='/css/style.css' />
  </head>
  <body>
  <% if (user) { %>
  <h1><%=user.userName%></h1>
  <% } %>

    <h1>所有用户数据</h1>
    <ul>
      <%if(result.length>0){%>

      <%for (var i=0;i<result.length;i++){%>
      <li>
        用户名：<%=result[i].userName%> 密码：<%=result[i].passWord%>
        呢称：<% if(result[i].nickName==null){ %>无<% }else{%><%=result[i].nickName%><%}%>
        性别：<%=result[i].sex%> 注册时间：<%=result[i].regTime%> 最近登录：<%=result[i].logTime%> 最近修改：<%=result[i].upTime%>
        <a href="edit?id=<%-result[i].id -%>">修改</a>
        <a href="javascript:;" onclick="userDel(<%-result[i].id -%>)">删除</a>
      </li>
      <%}%>

      <%}else{%>
      <li>暂无数据</li>
      <%}%>
    </ul>
  <a href="add">添加</a><br/><br/>

  <a href="/index">主页</a><br/><br/>

  <% if (user) { %>
  <a href="logout">退出登录</a>
  <%}else{%>
  <a href="login">登录</a>
  <%}%>

  <script src="/js/zepto.min.js"></script>
  
  <script>
    function userDel(id) {
        var msg = "您真的确定要删除吗？";
        if (confirm(msg)==true){
            $.ajax({
                type: "get",
                dataType: "JSON",
                url: 'del?id='+id,
                //data: {type:1,id:id},
                beforeSend: function(request) {
                    //request.setRequestHeader("token", token);
                },
                success: function (data) {
                    console.log(data);
                    data = $.parseJSON(data);
                    if(data.code==200){
                        alert('删除成功')
                        window.location.href="list";
                    }else{
                        alert('删除失败')
                    }
                },
                error: function(data) {
                    alert('请求失败')
                }
            });
        }else{
            return false;
        }

    }
  </script>

  </body>
</html>
